﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace WLive.WLiveObjects
{
    public class Audio : AFiles<Audio>
    {
        public From from;
        public int size;
        public string upload_location;
        public int comments_count;
        public bool comments_enabled;
        public bool is_embeddalbe;
        public string link;
        public string type;
        [Writable]
        public string title;
        [Writable]
        public string artist;
        [Writable]
        public string album;
        [Writable]
        public string album_artist;
        [Writable]
        public string gendre;
        public int duration;
        public string picture;
        public SharedWith shared_with;
        public DateTime created_time;
        public DateTime updated_time;

        /// <summary>
        /// 
        /// </summary>
        /// <returns>Returns audio picture if picture attribute is not empty otherwise null</returns>
        public Bitmap GetPicture()
        {
            if (!string.IsNullOrEmpty(picture))
            {
                try
                {
                    HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(picture);
                    HttpWebResponse wres = (HttpWebResponse)wreq.GetResponse();
                    return new Bitmap(wres.GetResponseStream());
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return null;
        }
    }
}
